<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MVC.
 *
 * PHP-MVC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MVC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MVC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-mvc
 * @subpackage  view
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */


/**
 * ActionMessage
 *
 * @category   Melange
 * @package    php-mvc
 * @subpackage action
 * @copyright  Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @license    http://www.gnu.org/licenses/licenses.html#GPL    The GNU General Public License
 */
class ActionMessage {


    // -------------------------------------------------------------- Constants


    const GLOBAL_MESSAGE = "nl.melange.phpmvc.action.GLOBAL_MESSAGE";


    // ----------------------------------------------------- Instance Variables


    /**
     * <p>The message key for this message.</p>
     */
    protected $key = null;


    /**
     * <p>The replacement values for this mesasge.</p>
     */
    protected $values = null;


    /**
     * <p>Indicates whether the key is taken to be as a  bundle key [true] or
     * literal value [false].</p>
     */
    protected $resource = false;


    // ----------------------------------------------------------- Constructors


    /**
     * <p>Construct an action message with the specified replacement
     * values.</p>
     *
     * @param key    Message key for this message
     * @param values Array of replacement values
     */
    public function __construct($key, $resource=false, $values=null) {
        $this->key = $key;
        $this->values = $values;
        $this->resource = $resource;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * <p>Get the message key for this message.</p>
     *
     * @return The message key for this message.
     */
    public function getKey() {
        return ($this->key);
    }


    /**
     * <p>Get the replacement values for this message.</p>
     *
     * @return The replacement values for this message.
     */
    public function getValues() {
        return ($this->values);
    }


    /**
     * <p>Indicate whether the key is taken to be as a  bundle key [true] or
     * literal value [false].</p>
     *
     * @return <code>true</code> if the key is a bundle key;
     *         <code>false</code> otherwise.
     */
    public function isResource() {
        return ($this->resource);
    }


    /**
     * <p>Returns a String in the format: key[value1, value2, etc].</p>
     *
     * @return String representation of this message
     * @see java.lang.Object#toString()
     */
    public function __toString() {

        $buff = "";

        $buff .= $this->key;
        $buff .= "[";

        if (!is_null($this->values)) {
            for ($i = 0; $i < count($this->values); $i++) {
                $buff .= $this->values[$i];

                // don't append comma to last entry
                if ($i < count($this->values) - 1) {
                    $buff .= ", ";
                }
            }
        }

        $buff .= "]";

        return $buff;
    }

}